package memory;


import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.Icon;
import java.awt.Color;
import java.io.Serializable;
import memory.net.ObjectDB;

@SuppressWarnings("serial")
public class Card extends JButton implements Serializable {
	
	public static enum State { DOLT, SYNLIGT, TAGET }

	private State status = State.TAGET;
	private Icon picture;
	
	//Used for network games
	private int id = ObjectDB.getID();
	
	public Card(Icon iconObj) {
		picture = iconObj;
		
		setStatus(State.TAGET);	
	}
	
	public Card(Icon iconObj, State initialStatus) {
		picture = iconObj;
		setStatus(initialStatus);		
	}
	
	public int getID() {
		return id;
	}

	public void setStatus(State newStatus) {
		
		if(newStatus == State.SYNLIGT) {
			this.setIcon(picture);
			this.setEnabled(false);			
		}
		else if(newStatus == State.DOLT) {
			this.setBackground(Color.blue);
			this.setIcon(null);
			this.setEnabled(true);
		}
		else if(newStatus == State.TAGET) {
			this.setBackground(Color.WHITE);
			this.setIcon(null);
			this.setEnabled(false);
		}
	
		status = newStatus;
		
		//Force redraw
		this.setEnabled(false);
		this.setEnabled(true);
		
		
	}
	
	public State getStatus() {
		return status;
	}
	
	public boolean equals(Card compareObj) {
		return ( this.picture == compareObj.picture );
	}
	
	public Card copy() {
		return new Card(this.picture, this.status);
	}

}
